package com.swagger.wen.controller;

import com.swagger.wen.bean.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("${server.error.path:${error.path:/error}}")
public class MyErrorController implements ErrorController {

    private static Logger LOGGER = LoggerFactory.getLogger(MyErrorController.class);

    @Override
    public String getErrorPath() {
        return "/error";
    }

    @RequestMapping
    @ResponseBody
    public JsonResult doHandleError(){
        LOGGER.error("这是MyErrorController报出的错误");
        JsonResult jsonResult = new JsonResult();
        jsonResult.setStatus("-1");
        jsonResult.setMsg("未知的错误发生");
        return jsonResult;
    }
}
